package com.pe.cineplanet.proyectocine.repository.hibernate;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import com.pe.cineplanet.proyectocine.domain.Combo;
import com.pe.cineplanet.proyectocine.repository.ComboRepository;
 
@Repository
public class ComboRepositoryHibernate extends HibernateDaoSupport 
implements ComboRepository{
	
	
	//constructor
	@Autowired
	public ComboRepositoryHibernate(SessionFactory sessionFactory) {
		setSessionFactory(sessionFactory);
	}

	public List<Combo> obtenerCombos() {
		return getHibernateTemplate().find("from Combo");   
	}

	public Combo obtenerCombo(int id_Combo) {
		return (Combo) getSession().createQuery("from Combo u where u.id_Combo=?").setInteger(0, id_Combo).uniqueResult();
	}

	public void grabarCombo(Combo obj) {
		getHibernateTemplate().saveOrUpdate(obj);
		
	}

	public void removerCombo(int id_Combo) {
		Combo obj = obtenerCombo(id_Combo);
		getHibernateTemplate().delete(obj);
		
		
	}

	public List<Combo> obtenerCombosActivos(boolean estado) {
		String sql = "from Combo u where u.sts_Combo=?";
		return getHibernateTemplate().find(sql, new Object[]{estado}); 
	}

}
